<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>upload</title>
</head>
<body>
<h1>ajaxupload-file</h1>


<input type="file" id = "file" >
<button type="button" onclick="uploadFile()">ajax上传</button>
<script type="text/javascript">
    function uploadFile() {
        var file = document.getElementById("file").files[0];
        //  // FormData 对象
        var  form = new FormData();
        form.append("file",file);
        form.append("source","weng")
        var xhr = new XMLHttpRequest();
        xhr.open("post","/ajaxupload",true);
        xhr.onload = function () {
             alert("上传成功")
        }
        xhr.send(form);

    }

</script>
</body>
</html>
